/*
 * @Author: NtyAaron
 * @Date: 2021-03-23 14:46:41
 * @LastEditors: NtyAaron
 * @LastEditTime: 2021-04-26 14:17:31
 * @Description: file content
 * @FilePath: \dwq\pages\kit\kit.js
 */
import { getQuestionList } from '../../api/kit/kit.js'
import { _t, _type } from '../../i18n/base'

Page({
  data: {
    active: 0,
    questionList: [],
    kitInfo: {
      // status: 1,
      type: 1,
    },
    lang: {},
    language: 1,
  },
  // 获取问题列表
  async getQuestionList(e) {
    e.status = this.data.language
    let { result } = await getQuestionList(e)
    if (result) {
      this.setData({
        questionList: result,
      })
    }
  },
  // 点击tab
  async tabSelectHandle(event) {
    this.setData({
      ['kitInfo.type']: event.detail.name,
    })
    this.getQuestionList(this.data.kitInfo)
  },
  // 跳转详情页
  toDetail(e) {
    let id = e.currentTarget.dataset.questionid
    wx.navigateTo({
      url: `/pages/kitDetail/kitDetail?questionid=${id}`,
    })
  },
  // 初始化登录状态
  initLoginStatus() {
    let userId = wx.getStorageSync('userId')
    if (!userId) {
      wx.switchTab({
        url: '/pages/index/index',
      })
    }
  },
  // 初始化
  onShow() {
    this.getQuestionList(this.data.kitInfo)
    // this.initLoginStatus()
  },
  onLoad(e) {
    console.log(e)
    this.setData({
      lang: _t(),
      language: _type(),
    })
    wx.setNavigationBarTitle({
      title: this.data.lang['关于'],
    })
  },
})
